package groupb6.shopsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import groupb6.shopsystem.mapper.ProductMapper;
import groupb6.shopsystem.pojo.entity.Product;
import groupb6.shopsystem.pojo.template.PageInfo;
import groupb6.shopsystem.service.CustomerHomepageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Queue;

@Service
public class CustomerHomepageServiceImpl implements CustomerHomepageService {
    @Autowired
    private ProductMapper productMapper;
    /*
    * 模糊分页查询商品记录
    * @author:zhangyn
    * */
    @Override
    public PageInfo findProductsByPage(Page page, String keyword) {
        LambdaQueryWrapper<Product> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(Product::getStatus, 1)
                .like(Product::getName,keyword)
                .or()
                .like(Product::getDetail,keyword)
                .orderByDesc(Product::getId)
                .eq(Product::getStatus, 1);
        IPage<Product> iPageProduct=productMapper.selectPage(page,wrapper);

        PageInfo pageInfo=new PageInfo<Product>();
        pageInfo.setData(iPageProduct.getRecords());
        pageInfo.setTotal((int) iPageProduct.getTotal());
        return pageInfo;
    }
}
